package net.csdn.business.common.config.ocr;

import com.aliyun.ocr_api20210707.Client;
import com.aliyun.oss.OSSClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName AliYunOcrConfig
 * @Description TODO
 * @Author lzs
 * @Date 2024/4/18
 **/
@Data
@Configuration
public class AliYunOcrConfig {
    @Value("${ali.ocr.accessKeyId:LTAI5tLkz7okbzutmeAY2R6r}")
    private String accessKeyId;

    @Value("${ali.ocr.accessKeySecret:fLt6sD3CNb61RyS28xr00TLabQs3pL}")
    private String accessKeySecret;

    @Value("${ali.ocr.oss.bucketName:atomgit-ocr}")
    private String bucketName;

    @Value("${ali.ocr.oss.endpoint:https://oss-cn-beijing.aliyuncs.com}")
    private String endpoint;

    @Value("${ali.ocr.oss.endpointWithBucket:https://atomgit.oss-cn-beijing.aliyuncs.com}")
    private String endpointWithBucket;

    private String enterpriseDir="uploads/enterprise/";

    private String[] ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "bmp", "gif", "webp", "pdf"};

    public Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
        return new Client(config);
    }

    public OSSClient createOSSClient(){
       return new OSSClient(endpoint, accessKeyId, accessKeySecret);
    }
}
